package com.xydtech.ecard.merchant.controller;


import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.domain.entity.SysDept;
import com.xydtech.common.core.domain.entity.SysDictData;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtilMap;
import com.xydtech.ecard.merchant.domain.EcardCustManagerMerchantPrd;
import com.xydtech.ecard.merchant.service.IEcardCustManagerMerchantPrdService;
import com.xydtech.system.mapper.SysDictDataMapper;
import com.xydtech.system.service.ISysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.LinkedHashMap;
import java.util.List;

/*
 * 客户经理营销商户产品信息查询
 *@author lin
 *@version 1.0
 *@create 2023/8/2 9:37
 */
@Controller
@RequestMapping("/merchant/custManagerMerchantPrd")
public class EcardCustManagerMerchantPrdController extends BaseController {
    @Autowired
    private IEcardCustManagerMerchantPrdService ecardCustManagerMerchantPrdService;
    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Autowired
    private ISysDeptService sysDeptService;


    private String prefix = "merchant";

    @RequiresPermissions("merchant:custManagerMerchantPrd:view")
    @GetMapping()
    public String merchant()
    {
        return prefix + "/custManagerMerchantPrd";
    }

    @RequiresPermissions("merchant:custManagerMerchantPrd:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardCustManagerMerchantPrd ecardCustManagerMerchantPrd) {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("ecard_merchant_business_tag", sysDept.getDeptId());
        startPage();
        List<LinkedHashMap<String, Object>> list = ecardCustManagerMerchantPrdService.selectCustManagerMerchantPrdInfo(ecardCustManagerMerchantPrd, sysDictDataList);
        return getDataTable(list);
    }

    /**
     * 获取指定类型的字典数据
     * @param dictType
     * @return
     */
    @RequiresPermissions("merchant:branchMerchantPrd:list")
    @PostMapping("/getMerchantPrdDict")
    @ResponseBody
    public AjaxResult getMerchantPrdDict(String dictType) {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("ecard_merchant_business_tag", sysDept.getDeptId());
        return AjaxResult.success(sysDictDataList);
    }

    @RequiresPermissions("merchant:custManagerMerchantPrd:export")
    @Log(title = "导出营销人员商户产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardCustManagerMerchantPrd ecardCustManagerMerchantPrd)
    {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("ecard_merchant_business_tag", sysDept.getDeptId());
        List<LinkedHashMap<String, Object>> list = ecardCustManagerMerchantPrdService.selectCustManagerMerchantPrdInfo(ecardCustManagerMerchantPrd, sysDictDataList);
        return ExcelUtilMap.getInstance().createExcel(list, "营销人员商户产品信息", "营销人员商户产品信息");
    }
}
